package com.margo.project.netty.redis;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * redis客户端
 * @author fangxingbang
 *
 */
public class RedisClient {
	public static void main(String[] args) {
		EventLoopGroup group=new NioEventLoopGroup();
		Bootstrap bootstrap=new Bootstrap();
		bootstrap.group(group).channel(NioSocketChannel.class).handler(new RedisClientInitializer());
		
		try {
			Channel channel=bootstrap.connect("localhost", 6379).sync().channel();
			ChannelFuture channelFuture=channel.writeAndFlush("set hello 123");
			channelFuture.addListener((future)->{
				if(!future.isSuccess()) {
					System.out.println("失败了");
				}
			});
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
